package com.example.androidtraining_ahut2020;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivityDay09IntentDemo1 extends AppCompatActivity {
    Button btnCall, btnSendMsg, btnOpenURL;
    private View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.btnCall:
                    Log.i("IntentDemo", "btnCall~");
                    Intent i = new Intent();
                    i.setAction(Intent.ACTION_CALL);
                    i.setData(Uri.parse("tel:2222"));
                    startActivity(i);
                    break;
                case R.id.btnSendMsg:
                    Intent i2 = new Intent();
                    i2.setAction(Intent.ACTION_SENDTO);
                    i2.setData(Uri.parse("smsto:5554"));
                    i2.putExtra("sms_body", "aaaaaaaaaaaaaaaa");
                    startActivity(i2);
                    break;
                case R.id.btnOpenURL:
                    Intent i3 = new
                            Intent(Intent.ACTION_VIEW, Uri.parse("http://www.baidu.com"));
                    startActivity(i3);
                    break;
                default:
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_day09_intent_demo1);
        btnCall = super.findViewById(R.id.btnCall);
        btnSendMsg = super.findViewById(R.id.btnSendMsg);
        btnOpenURL = super.findViewById(R.id.btnOpenURL);
        btnCall.setOnClickListener(listener);
        btnSendMsg.setOnClickListener(listener);
        btnOpenURL.setOnClickListener(listener);
    }
}